<template>
  <section>
    <div
      :class="value === item.value ? 'current' : ''"
      class="item"
      v-for="(item, ind) in options"
      :key="ind"
      @click="selectItem(item, ind)"
    >
      {{ item.label }}
    </div>
  </section>
</template>

<script>
import { deepClone } from "@/utils";

export default {
  name: "selectCom",
  model: {
    prop: "currentItem",
    event: "change",
  },
  data() {
    return {
      index: 0,
      currentItem: null,
      value: undefined,
    };
  },
  props: {
    options: {
      type: [Array],
    },
    defaultValue: {
      type: String,
      default: "",
    },
  },
  mounted() {
    this.value = this.defaultValue;
  },
  methods: {
    // 选择
    selectItem(item, index) {
      console.log("选项变化>>>", item, index);
      this.value = item.value;
      this.currentItem = deepClone(item);
      this.$emit("change", this.currentItem.value);
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  position: relative;
  display: inline-block;
  width: 120px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #b0b0b0;
  border: 1px solid #b0b0b0;
  margin-right: 25px;
  border-radius: 5px;
  cursor: pointer;
}
.current {
  color: #4677b9;
  border: 1px solid #4677b9;
  &:after {
    content: "";
    display: block;
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 28px;
    height: 27px;
    overflow: hidden;
    background: url("../../../assets/images/confirm-icon.png") no-repeat center
      center / cover;
  }
}
</style>
